package io.github.talelin.latticy.controller.v1;

import io.github.talelin.core.annotation.LoginRequired;
import io.github.talelin.latticy.model.oms.AreaDO;
import io.github.talelin.latticy.service.AreaService;
import io.github.talelin.latticy.vo.CreatedVO;
import io.github.talelin.latticy.vo.DeletedVO;
import io.github.talelin.latticy.vo.PageResponseVO;
import io.github.talelin.latticy.vo.UpdatedVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.Positive;
import java.util.List;

/**
 * @author generator@wulongbo
 * @since 2022-05-11
 */

@Validated
@RestController
@RequestMapping("/v1/area")
public class AreaController {

    @Autowired
    private AreaService areaService;

    @PostMapping("")
    public CreatedVO create() {
        return new CreatedVO();
    }

    @PutMapping("/{id}")
    @LoginRequired
    public UpdatedVO update(@PathVariable @Positive(message = "{id.positive}") Integer id) {
        return new UpdatedVO();
    }

    @DeleteMapping("/{id}")
    @LoginRequired
    public DeletedVO delete(@PathVariable @Positive(message = "{id.positive}") Integer id) {
        return new DeletedVO();
    }

    @GetMapping("/{id}")
    @LoginRequired
    public AreaDO get(@PathVariable(value = "id") @Positive(message = "{id.positive}") Integer id) {
        return null;
    }

    @GetMapping("region/all")
    @LoginRequired
    public List<AreaDO> getCJERegion() {
        return areaService.getCJERegion();
    }

    @GetMapping("/all/{id}")
    @LoginRequired
    public List<AreaDO> getAllArea(@PathVariable @Positive(message = "{region.id.positive}") Integer id) {
        return areaService.getAllArea(id);
    }

    @GetMapping("/province/{id}")
    @LoginRequired
    public List<AreaDO> getProvinces(@PathVariable @Positive(message = "{province.id.positive}") Integer id) {
        return areaService.getProvinces(id);
    }

    @GetMapping("/city/{id}")
    @LoginRequired
    public List<AreaDO> getCitys(@PathVariable @Positive(message = "{city.id.positive}") Integer id) {
        return areaService.getCitys(id);
    }

    @GetMapping("/page")
    public PageResponseVO<AreaDO> page(
            @RequestParam(name = "page", required = false, defaultValue = "0")
            @Min(value = 0, message = "{page.number.min}") Integer page,
            @RequestParam(name = "count", required = false, defaultValue = "10")
            @Min(value = 1, message = "{page.count.min}")
            @Max(value = 30, message = "{page.count.max}") Integer count
    ) {
        return null;
    }

}
